package com.xiezc.data.util;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 字段自动填充处理器
 *
 * @author wb-xzc291800
 * @date 2018/10/10 17:49
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Object updateTime = metaObject.getValue("updateTime");
        if (updateTime == null) {
            metaObject.setValue("updateTime", LocalDateTime.now());
        }

        Object createTime = metaObject.getValue("createTime");
        if (createTime == null) {
            metaObject.setValue("createTime", LocalDateTime.now());
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Object updateTime = metaObject.getValue("updateTime");
        if (updateTime == null) {
            metaObject.setValue("updateTime", LocalDateTime.now());
        }
    }
}
